package com.qq.xrx1002.androidgame;

import org.cocos2d.actions.base.CCRepeatForever;
import org.cocos2d.actions.interval.CCAnimate;
import org.cocos2d.nodes.CCAnimation;
import org.cocos2d.nodes.CCSprite;
import org.cocos2d.nodes.CCSpriteFrame;

import java.util.ArrayList;
import java.util.Locale;

/**
 * Created by Alyson on 2018/11/14.
 */

public class WallNut extends Plant {//太阳花
    public WallNut() {
        //number表示图片又多少帧就写多少的数字
        super("plant/WallNut/high/Frame%02d.png", 16);
        setPrice(50);
        setHP(600);
    }
    @Override
    public void hurtCompute(int hurt) {
        super.hurtCompute(hurt);
        if (getHP()>=200&&getHP()<=400){
            stopAllActions();
            ArrayList<CCSpriteFrame> frames=new ArrayList<>();
            for (int i = 0; i <11 ; i++) {//总共19张图片
                CCSpriteFrame ccSpriteFrame= CCSprite.sprite(String.format(Locale.CHINA,//Locale.CHINA：使用的语言为中文
                        "plant/WallNut/middle/Frame%02d.png",i)).displayedFrame();//2位的帧序列的使用
                frames.add(ccSpriteFrame);
            }
            CCAnimation ccAnimation=CCAnimation.animationWithFrames(frames,0.2f);//CCAnimation：帧动画；frames,0.2f：0.2秒执行一帧
            CCAnimate ccAnimate=CCAnimate.action(ccAnimation,true);//帧动画是否重复，false表示不重复。也可以不写
            CCRepeatForever ccRepeatForever=CCRepeatForever.action(ccAnimate);
            runAction(ccRepeatForever);
        }
        if (getHP()<200){
            stopAllActions();
            ArrayList<CCSpriteFrame>frames=new ArrayList<>();
            for (int i = 0; i <15 ; i++) {//总共19张图片
                CCSpriteFrame ccSpriteFrame= CCSprite.sprite(String.format(Locale.CHINA,//Locale.CHINA：使用的语言为中文
                        "plant/WallNut/low/Frame%02d.png",i)).displayedFrame();//2位的帧序列的使用
                frames.add(ccSpriteFrame);
            }
            CCAnimation ccAnimation=CCAnimation.animationWithFrames(frames,0.2f);//CCAnimation：帧动画；frames,0.2f：0.2秒执行一帧
            CCAnimate ccAnimate=CCAnimate.action(ccAnimation,true);//帧动画是否重复，false表示不重复。也可以不写
            CCRepeatForever ccRepeatForever=CCRepeatForever.action(ccAnimate);
            runAction(ccRepeatForever);
        }
    }
}
